package com.tfjybj.itoo.exam.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.TemplateDetailsExtractEntity;
import com.tfjybj.itoo.exam.model.QuestionMainModel;
import com.tfjybj.itoo.exam.model.TemplateDetailsExtractModel;
import com.tfjybj.itoo.exam.provider.service.TemplateDetailsExtractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * TemplateDetailsExtractController
 * templateDetailsExtract表
 *
 * @author 任晓帅
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 19:40:28
 */
@Api(tags = {"templateDetailsExtract表接口"})
@RequestMapping(value = "/templateDetailsExtract")
@RestController
public class TemplateDetailsExtractController {

    @Resource
    private TemplateDetailsExtractService templateDetailsExtractService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model TemplateDetailsExtractModel
     * @return 添加的结果
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody TemplateDetailsExtractModel model) {
		if (StringUtils.isEmpty(model.getQuestionId())){
            return ItooResult.build(ItooResult.FAIL, "questionId为空");
        }
		if (StringUtils.isEmpty(model.getTemplateDetailsId())){
            return ItooResult.build(ItooResult.FAIL, "templateDetailsId为空");
        }
        TemplateDetailsExtractEntity templateDetailsExtractEntity = new TemplateDetailsExtractEntity();
        BeanUtils.copyProperties(model, templateDetailsExtractEntity);
        templateDetailsExtractService.save(templateDetailsExtractEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        templateDetailsExtractService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiParam( value = "ids", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        templateDetailsExtractService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model TemplateDetailsExtractModel
     * @return 修改后的结果
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id修改templateDetailsExtract")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody TemplateDetailsExtractModel model) {
		if (StringUtils.isEmpty(model.getQuestionId())){
            return ItooResult.build(ItooResult.FAIL, "questionId为空");
        }
		if (StringUtils.isEmpty(model.getTemplateDetailsId())){
            return ItooResult.build(ItooResult.FAIL, "templateDetailsId为空");
        }
        TemplateDetailsExtractEntity templateDetailsExtractEntity = new TemplateDetailsExtractEntity();
        BeanUtils.copyProperties(model, templateDetailsExtractEntity);
        templateDetailsExtractService.updateById(templateDetailsExtractEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找TemplateDetailsExtract
     *
     * @param id 主键id
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        TemplateDetailsExtractEntity templateDetailsExtractEntity = templateDetailsExtractService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsExtractEntity);
    }

    /**
     * 分页查询所有TemplateDetailsExtract
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "分页查询所有TemplateDetailsExtract")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo,
								   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<TemplateDetailsExtractEntity> templateDetailsExtracts = templateDetailsExtractService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsExtracts);
    }
	
	/**
     * 根据试题id模糊查询templateDetailsExtract
     *
     * @param questionId  试题id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的templateDetailsExtract
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据试题id模糊查询templateDetailsExtract", notes = "分页根据试题id模糊查询templateDetailsExtract")
    @GetMapping(value = "queryTemplateDetailsExtractByLikeQuestionId/{pageNo}/{pageSize}")
    public ItooResult queryTemplateDetailsExtractByLikeQuestionId(@RequestParam(required = false, defaultValue = "") String questionId,
                                                                  @ApiParam(value = "页码",  required = true, example = "1") @PathVariable Integer pageNo,
                                                                  @ApiParam(value = "记录数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<TemplateDetailsExtractEntity> templateDetailsExtractList = templateDetailsExtractService.queryByLikeQuestionId(questionId, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsExtractList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */
/**
 * 根据模板详情id查询templateDetailsExtract
 *
 * @param templatedetailsId  模板详情id
 * @return 查询的templateDetailsExtract
 * @author 杨海云
 * @since 2.0.0 2018-11-27 19:40:28
 */
    @ApiOperation(value = "根据模板详情id查询templateDetailsExtract")
    @GetMapping(value = "/queryQueExtractByTemplateId/{templatedetailsId}")
    public ItooResult queryQueExtractByTemplateId(@ApiParam(value = "模板详情id",required = true)@PathVariable String templatedetailsId){
           List<QuestionMainModel> questionMainModelList = templateDetailsExtractService.queryQueExtractByTemplateId(templatedetailsId);
           return ItooResult.build(ItooResult.SUCCESS,"查询成功",questionMainModelList);
    }
    /**
     * 根据模板详情id查询templateDetailsExtract
     * @param templateDetsilsId  模板详情id
     * @return 查询的templateDetailsExtract
     * @author 杨海云
     * @since 2.0.0 2018-11-29 19:40:28
     *
     */
    @ApiOperation(value = "根据模板详情id查询templateDetailsExtract")
    @GetMapping(value = "/queryDetilsExtractBytemplateDetailsId/{templateDetsilsId}")
    public ItooResult queryDetilsExtractBytemplateDetailsId(@ApiParam(value = "模板详情id",required = true)@PathVariable String templateDetsilsId){
        List<TemplateDetailsExtractEntity> templateDetailsExtractEntityList =templateDetailsExtractService.queryDetilsExtractBytemplateDetailsId(templateDetsilsId);
        return ItooResult.build(ItooResult.SUCCESS,"查询成功",templateDetailsExtractEntityList);
    }

}    
